package properties;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Properties;

public class Config extends Properties{

	private static final long serialVersionUID = 1L;
	
	private static Config config=null;
	
	private final static String path = "config/config.properties";

	private Config() throws IOException {
		InputStreamReader input = new InputStreamReader(new FileInputStream(new File(path)));
		this.load(input);
	}
	
	public static Config getInstance() throws IOException  {
		if(config==null){
			config=new Config();
		}
		return config;
	}
	
	public String getString(String key){
		return getProperty(key);
	}
	
	public int getInteger(String key){
		return new Integer(getProperty(key));
	}

	public double getDouble(String key){
		return new Double(getProperty(key));
	}
	
	public float getFloat(String key){
		return new Float(getProperty(key));
	}
	
	public static void store(){
		try {
			OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(new File(path)));
			config.store(out,"");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
